package com.fangmao.a04_retrofit;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.List;

import androidx.annotation.Nullable;
import okhttp3.internal.platform.Platform;
import retrofit2.Call;

/**
 * @ProjectName: wman
 * @Package: com.fangmao.a04_retrofit
 * @ClassName: RealService
 * @Description: java类作用描述
 * @Author: wman
 * @CreateDate: 2020/2/14 14:47
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/2/14 14:47
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class RealService implements GitHubService {
    InvocationHandler mInvocationHandler = new InvocationHandler() {
        private final Platform platform = Platform.get();
        private final Object[] emptyArgs = new Object[0];

        @Override
        public @Nullable
        Object invoke(Object proxy, Method method,
                      @Nullable Object[] args) throws Throwable {
            // If the method is a method from Object then defer to normal invocation.
//            if (method.getDeclaringClass() == Object.class) {
//                return method.invoke(this, args);
//            }
//            if (platform.isDefaultMethod(method)) {
//                return platform.invokeDefaultMethod(method, service, proxy, args);
//            }
//            return loadServiceMethod(method).invoke(args != null ? args : emptyArgs);
            return null;
        }
    };

    @Override
    public Call<List<Repo>> listRepos(String user) {
        Method method = null;
        try {
            method = GitHubService.class.getMethod("listRepos");
            return (Call<List<Repo>>) mInvocationHandler.invoke(this, method, null);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } finally {
            return null;
        }
    }
}
